package com.xiyi.shouxin.utils;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

public class BeanUtil {
    // 获取具有public修饰的get方法的字段
    public static List<Field> findGetMethodsField(Class<?> clazz) {
        List<Field> fieldsWithGetMethods = new ArrayList<>();
        Method[] methods = clazz.getMethods();
        Field[] fields = clazz.getDeclaredFields();

        for (Field field : fields) {
            String getMethodName = "GET" + field.getName().toUpperCase();
            boolean hasGetMethod = false;
            for (Method method : methods) {
                if (method.getName().toUpperCase().equals(getMethodName) && method.getParameterCount() == 0) {
                    hasGetMethod = true;
                    break;
                }
            }
            if (hasGetMethod) {
                fieldsWithGetMethods.add(field);
            }
        }

        return fieldsWithGetMethods;
    }
}
